package com.antxon.cliente;


import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;

public class ClienteDAO {
	
	@SessionTarget
	Session session;
	
	@TransactionTarget
	Transaction transaction;
	

	/**
	 * Used to save or update a user.
	 */
	public void guardarOActualizarCliente(Cliente cliente) {
		try {
			session.saveOrUpdate(cliente);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		}
	}

	/**
	 * Used to delete a user.
	 */
	public void eliminarCliente(Long id) {
		try {
			Cliente cliente = (Cliente) session.get(Cliente.class, id);
			session.delete(cliente);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		} 
	}
	
	/**
	 * Used to list all the users.
	 */
	@SuppressWarnings("unchecked")
	public List<Cliente> listarClientes(){
		List<Cliente> cliente = null;
		try {
			cliente = session.createQuery("from Cliente").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cliente;
	}

	/**
	 * Used to list all the users.
	 */
	

}
